000100******************************************************************
000200*PROGRAM : Report Zip
000300*AUTHOR  : Minh-Tuan Ta
000400*DATE    : 02/13/12
000500******************************************************************
000600 IDENTIFICATION DIVISION.
000700 PROGRAM-ID. RPTZIP.
000800 ENVIRONMENT DIVISION.
000900     SELECT INFILE   ASSIGN TO "ZIPFILE.DAT"
001000                     ORGANIZATION    IS  INDEXED
001100                     ACCESS          IS  DYNAMIC
001200                     RECORD KEY      IS  IN-ZIP
001300                     ALTERNATE KEY   IS  IN-CITY WITH DUPLICATES
001400                     FILE STATUS     IS  WS-STAT.
001500 DATA DIVISION.
001600 FILE SECTION.
001700 FD  INFILE.
001800 01  IN-REC.
001900     03  IN-ZIP      PIC X(5).
002000     03  IN-CITY     PIC X(30).
002100     03  IN-STATE    PIC X(2).
002200     03  IN-COUNTY   PIC X(30).
002300 WORKING-STORAGE SECTION.
002400 01  WS-VARS.
002500     03  WS-DATE.
002600         05  WS-YEAR         PIC 99.
002700         05  WS-MONTH        PIC 99.
002800         05  WS-DAY          PIC 99.
002900     03  WS-CITY             PIC X(30).
003000     03  WS-STAT             PIC X(2).
003100     03  WS-CONTINUE         PIC X.
003200     03  WS-EOF              PIC X   VALUE "N".
003300     03  WS-LOOP-CNT         PIC 99  VALUE ZEROS.
003400     03  WS-CNT              PIC 999 VALUE ZEROS.
003500 01  OUT-ARRAY.
003600 03      OUT-RECORDS OCCURS 20 TIMES.
003700             05  OUT-NO      PIC 9(3)    VALUE 1.
003800             05  FILLER      PIC X       VALUE SPACES.
003900             05  OUT-ZIP     PIC X(5)    VALUE SPACES.
004000             05  FILLER      PIC X       VALUE SPACES.
004100             05  OUT-CITY    PIC X(30)   VALUE SPACES.
004200             05  FILLER      PIC X       VALUE SPACES.
004300             05  OUT-STATE   PIC X(2)    VALUE SPACES.
004400             05  FILLER      PIC X       VALUE SPACES.
004500             05  OUT-COUNTY  PIC X(30)   VALUE SPACES.
004600
004700 SCREEN SECTION.
004800 01  ENTER-SCRN.
004900     03  BLANK SCREEN.
005000     03  MENU.
005100         05  LINE 1  COL 01  VALUE "ZIPC-INQCITY".
005200         05          COL 73  PIC 9(2) FROM WS-MONTH.
005300         05          COL 75  VALUE "/".
005400         05          COL 76  PIC 9(2) FROM WS-DAY.
005500         05          COL 78  VALUE "/".
005600         05          COL 79  PIC 9(2) FROM WS-YEAR.
005700         05          COL 34  VALUE "ZIP CODE SYSTEM".
005800         05  LINE 2  COL 37  VALUE "CITY INQUIRY".
005900         05  LINE 4  COL 20  VALUE "CITY".
006000         05          COL 29  PIC X(30) TO WS-CITY.
006100 01  DISPLAY-SCRN.
006200     03  BLANK SCREEN.
006300     03  DISPLAY-REC.
006400         05  LINE 1  COL 01  VALUE "ZIPC-INQCITY".
006500         05          COL 73  PIC 9(2) FROM WS-MONTH.
006600         05          COL 75  VALUE "/".
006700         05          COL 76  PIC 9(2) FROM WS-DAY.
006800         05          COL 78  VALUE "/".
006900         05          COL 79  PIC 9(2) FROM WS-YEAR.
007000         05          COL 34  VALUE "ZIP CODE SYSTEM".
007100         05  LINE 2  COL 36  VALUE "CITY INQUIRY".
007200         05  LINE 4  COL 4   PIC X(74) FROM  OUT-RECORDS(1).
007300         05  LINE 5  COL 4   PIC X(74) FROM  OUT-RECORDS(2).
007400         05  LINE 6  COL 4   PIC X(74) FROM  OUT-RECORDS(3).
007500         05  LINE 7  COL 4   PIC X(74) FROM  OUT-RECORDS(4).
007600         05  LINE 8  COL 4   PIC X(74) FROM  OUT-RECORDS(5).
007700         05  LINE 9  COL 4   PIC X(74) FROM  OUT-RECORDS(6).
007800         05  LINE 10 COL 4   PIC X(74) FROM  OUT-RECORDS(7).
007900         05  LINE 11 COL 4   PIC X(74) FROM  OUT-RECORDS(8).
008000         05  LINE 12 COL 4   PIC X(74) FROM  OUT-RECORDS(9).
008100         05  LINE 13 COL 4   PIC X(74) FROM  OUT-RECORDS(10).
008200         05  LINE 14 COL 4   PIC X(74) FROM  OUT-RECORDS(11).
008300         05  LINE 15 COL 4   PIC X(74) FROM  OUT-RECORDS(12).
008400         05  LINE 16 COL 4   PIC X(74) FROM  OUT-RECORDS(13).
008500         05  LINE 17 COL 4   PIC X(74) FROM  OUT-RECORDS(14).
008600         05  LINE 18 COL 4   PIC X(74) FROM  OUT-RECORDS(15).
008700         05  LINE 19 COL 4   PIC X(74) FROM  OUT-RECORDS(16).
008800         05  LINE 20 COL 4   PIC X(74) FROM  OUT-RECORDS(17).
008900         05  LINE 21 COL 4   PIC X(74) FROM  OUT-RECORDS(18).
009000         05  LINE 22 COL 4   PIC X(74) FROM  OUT-RECORDS(19).
009100         05  LINE 23 COL 4   PIC X(74) FROM  OUT-RECORDS(20).
009200         05  LINE 25 COL 18  VALUE "PRESS ENTER TO CONTINUE, OR 'X
009300-                                  "' TO EXIT".
009400         05          COL 58  PIC X   TO  WS-CONTINUE AUTO.
009500
009600 01  DISPLAY-EOF-SCRN.
009700     03  BLANK SCREEN.
009800     03  DISPLAY-REC.
009900         05  LINE 1  COL 01  VALUE "ZIPC-INQCITY".
010000         05          COL 73  PIC 9(2) FROM WS-MONTH.
010100         05          COL 75  VALUE "/".
010200         05          COL 76  PIC 9(2) FROM WS-DAY.
010300         05          COL 78  VALUE "/".
010400         05          COL 79  PIC 9(2) FROM WS-YEAR.
010500         05          COL 34  VALUE "ZIP CODE SYSTEM".
010600         05  LINE 2  COL 36  VALUE "CITY INQUIRY".
010700         05  LINE 4  COL 4   PIC X(74) FROM  OUT-RECORDS(1).
010800         05  LINE 5  COL 4   PIC X(74) FROM  OUT-RECORDS(2).
010900         05  LINE 6  COL 4   PIC X(74) FROM  OUT-RECORDS(3).
011000         05  LINE 7  COL 4   PIC X(74) FROM  OUT-RECORDS(4).
011100         05  LINE 8  COL 4   PIC X(74) FROM  OUT-RECORDS(5).
011200         05  LINE 9  COL 4   PIC X(74) FROM  OUT-RECORDS(6).
011300         05  LINE 10 COL 4   PIC X(74) FROM  OUT-RECORDS(7).
011400         05  LINE 11 COL 4   PIC X(74) FROM  OUT-RECORDS(8).
011500         05  LINE 12 COL 4   PIC X(74) FROM  OUT-RECORDS(9).
011600         05  LINE 13 COL 4   PIC X(74) FROM  OUT-RECORDS(10).
011700         05  LINE 14 COL 4   PIC X(74) FROM  OUT-RECORDS(11).
011800         05  LINE 15 COL 4   PIC X(74) FROM  OUT-RECORDS(12).
011900         05  LINE 16 COL 4   PIC X(74) FROM  OUT-RECORDS(13).
012000         05  LINE 17 COL 4   PIC X(74) FROM  OUT-RECORDS(14).
012100         05  LINE 18 COL 4   PIC X(74) FROM  OUT-RECORDS(15).
012200         05  LINE 19 COL 4   PIC X(74) FROM  OUT-RECORDS(16).
012300         05  LINE 20 COL 4   PIC X(74) FROM  OUT-RECORDS(17).
012400         05  LINE 21 COL 4   PIC X(74) FROM  OUT-RECORDS(18).
012500         05  LINE 22 COL 4   PIC X(74) FROM  OUT-RECORDS(19).
012600         05  LINE 23 COL 4   PIC X(74) FROM  OUT-RECORDS(20).
012700         05  LINE 25 COL 18  VALUE "END OF FILE, PRESS ENTER TO CO
012800-                                  "NTINUE".
012900         05          COL 58  PIC X   TO  WS-CONTINUE AUTO.
013000
013100 PROCEDURE DIVISION.
013200 100-MAIN.
013300     ACCEPT WS-DATE FROM DATE
013400     OPEN INPUT INFILE
013500     DISPLAY ENTER-SCRN
013600     ACCEPT  ENTER-SCRN
013700     MOVE    WS-CITY TO IN-CITY
013800     PERFORM UNTIL WS-CITY = 'XXX' OR 'xxx'
013900         MOVE "N" TO WS-EOF
014000         MOVE 1 TO WS-CNT
014100         MOVE SPACES TO WS-CONTINUE
014200         START INFILE KEY >= IN-CITY
014300         END-START
014400         PERFORM 200-DISPLAY
014500         DISPLAY ENTER-SCRN
014600         ACCEPT  ENTER-SCRN
014700         MOVE    WS-CITY TO IN-CITY
014800     END-PERFORM
014900     CLOSE INFILE
015000
015100     EXIT PROGRAM.
015200
015300 200-DISPLAY.
015400     PERFORM UNTIL ((WS-EOF = "Y") OR
015500     ((WS-CONTINUE = "X" OR WS-CONTINUE = "x") AND WS-EOF = "N"))
015600         PERFORM 300-INIT-ARRAY
015700         PERFORM 400-READ-INPUT
015800         IF WS-EOF = "Y"
015900             DISPLAY DISPLAY-EOF-SCRN
016000             ACCEPT DISPLAY-EOF-SCRN
016100         ELSE
016200             DISPLAY DISPLAY-SCRN
016300             ACCEPT DISPLAY-SCRN
016400         END-IF
016500     END-PERFORM.
016600
016700 300-INIT-ARRAY.
016800     MOVE 1 TO WS-LOOP-CNT
016900     PERFORM UNTIL WS-LOOP-CNT > 20
017000         MOVE SPACES TO OUT-RECORDS(WS-LOOP-CNT)
017100         ADD 1 TO WS-LOOP-CNT
017200     END-PERFORM.
017300
017400 400-READ-INPUT.
017500     READ INFILE NEXT RECORD
017600         AT END MOVE 'Y' TO WS-EOF
017700     END-READ
017800     MOVE 1 TO WS-LOOP-CNT
017900     PERFORM UNTIL WS-LOOP-CNT > 20 OR WS-EOF = "Y"
018000         MOVE WS-CNT     TO OUT-NO(WS-LOOP-CNT)
018100         MOVE IN-ZIP     TO OUT-ZIP(WS-LOOP-CNT)
018200         MOVE IN-CITY    TO OUT-CITY(WS-LOOP-CNT)
018300         MOVE IN-STATE   TO OUT-STATE(WS-LOOP-CNT)
018400         MOVE IN-COUNTY  TO OUT-COUNTY(WS-LOOP-CNT)
018500         READ INFILE NEXT RECORD
018600             AT END MOVE 'Y' TO WS-EOF
018700         END-READ
018800         ADD 1 TO WS-LOOP-CNT
018900         IF WS-CNT = 999
019000             MOVE 1 TO WS-CNT
019100         ELSE
019200             ADD 1 TO WS-CNT
019300         END-IF
019400     END-PERFORM.
019500
